#!/bin/bash

CLEAN_STATUS=$1
START_STATUS=$2

if [ $CLEAN_STATUS == 'KillServers' ];
then
    echo "Killing Existing Selenium Instances..."
    kill -9 `ps -ef | grep "selenium" | grep -v grep | awk '{print $2}'`
    sleep 5
fi

if [ $START_STATUS == 'StartServers' ];
then
    echo "Moving to Selenium base directory.."
    cd ../selenium

    echo "Starting Selenium Hub. Please wait.."
    gnome-terminal -e "nohup java -jar selenium-server-standalone-2.32.0.jar -role hub" &
    sleep 15

    echo "Starting Selenium FireFox Node. Please wait.."
    gnome-terminal -e "nohup java -jar selenium-server-standalone-2.32.0.jar -role webdriver -hub http://localhost:4444/grid/register -maxSession 10 -timeout 10000 -browser browserName=firefox,maxInstances=10 -port 5555" &
    sleep 5

    echo "Starting Selenium Chrome Node. Please wait.."
    gnome-terminal -e "nohup java -jar selenium-server-standalone-2.32.0.jar -Dwebdriver.chrome.driver=chromedriver -role webdriver -hub http://localhost:4444/grid/register -maxSession 10 -timeout 10000 -browser browserName=chrome,maxInstances=10 -port 5557" &
    sleep 5
fi

echo "Defined process done."
